package org.shoukaiseki.supersaiyan.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.shoukaiseki.common.domain.DetailParam;
import org.shoukaiseki.supersaiyan.common.core.page.TableDataInfo;
import org.shoukaiseki.supersaiyan.system.domain.qo.SysOrganizeQO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.shoukaiseki.supersaiyan.common.annotation.Log;
import org.shoukaiseki.supersaiyan.common.core.controller.BaseController;
import org.shoukaiseki.supersaiyan.common.core.domain.base.AjaxResult;
import org.shoukaiseki.supersaiyan.common.enums.BusinessType;
import org.shoukaiseki.supersaiyan.system.domain.SysOrganize;
import org.shoukaiseki.supersaiyan.system.service.ISysOrganizeService;
import org.shoukaiseki.supersaiyan.common.utils.poi.ExcelUtil;

/**
 * 组织限制Controller
 *
 * @author shoukaiseki
 * @date 2022-11-01
 */
@RestController
@RequestMapping("/system/organize")
public class SysOrganizeController extends BaseController
{
    @Autowired
    private ISysOrganizeService sysOrganizeService;

    /**
     * 查询组织限制列表
     */
    @PreAuthorize("@ss.hasPermi('system:organize:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody SysOrganizeQO param)
    {
        List<SysOrganize> list = sysOrganizeService.selectSysOrganizeList(param);
        return AjaxResult.successPage(list);
    }

    /**
     * 导出组织限制列表
     */
    @PreAuthorize("@ss.hasPermi('system:organize:export')")
    @Log(title = "组织限制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody SysOrganizeQO param)
    {
        List<SysOrganize> list = sysOrganizeService.selectSysOrganizeList(param);
        ExcelUtil<SysOrganize> util = new ExcelUtil<SysOrganize>(SysOrganize.class);
        util.exportExcel(response, list, "组织限制数据");
    }

    /**
     * 获取组织限制详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:organize:query')")
    @PostMapping(value = "/getInfo")
    public AjaxResult getInfo(@RequestBody DetailParam param)
    {
        return AjaxResult.successData(sysOrganizeService.selectSysOrganizeByOrgId(param.getId()));
    }

    /**
     * 新增组织限制
     */
    @PreAuthorize("@ss.hasPermi('system:organize:add')")
    @Log(title = "组织限制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOrganize sysOrganize)
    {
        return toAjax(sysOrganizeService.insertSysOrganize(sysOrganize));
    }

    /**
     * 修改组织限制
     */
    @PreAuthorize("@ss.hasPermi('system:organize:edit')")
    @Log(title = "组织限制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOrganize sysOrganize)
    {
        return toAjax(sysOrganizeService.updateSysOrganize(sysOrganize));
    }

    /**
     * 删除组织限制
     */
    @PreAuthorize("@ss.hasPermi('system:organize:remove')")
    @Log(title = "组织限制", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orgIds}")
    public AjaxResult remove(@PathVariable Long[] orgIds)
    {
        return toAjax(sysOrganizeService.deleteSysOrganizeByOrgIds(orgIds));
    }
}
